#pragma once

#include <set>
#include <string>
#include <memory>

#include <Windows.h>
#include <Cchannel.h>

#include <boost/noncopyable.hpp>
#include <boost/thread/shared_mutex.hpp>

namespace rdc_transport
{
    struct ICliChannalCore;

    class ClientChannelManager: private boost::noncopyable
    {
    private:
        typedef ICliChannalCore* pClientChannel;

    public:
        void ChannelInitEventProc(LPVOID pInitHandle, UINT event, LPVOID pData, UINT dataLength) throw();
        void ChannelOpenEventProc(DWORD openHandle, UINT event, LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags) throw();
        
    public:
        void AddChannel(ICliChannalCore* channel);
        void DeleteChannel(ICliChannalCore* channel);

    private:
        std::set<pClientChannel> m_channels;

        boost::shared_mutex m_channelsAcessLock;
    };

    void VCAPITYPE ChannelInitEventProc(LPVOID pInitHandle, UINT event, LPVOID pData, UINT dataLength);
    void VCAPITYPE ChannelOpenEventProc(DWORD  openHandle, UINT   event, LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags);

    // Return global manager object.
    ClientChannelManager* GetClientChannelManager() throw();
}
